package com.cudex.negocio.beans;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;

/**
 * @author Nicolas Bordenave
 * @date 22/11/2011
 * @version 1.0
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "buscarClientes", query = "SELECT c FROM Clientes c"),
		@NamedQuery(name = "buscarCliente", query = "SELECT c FROM Clientes c WHERE c =:Cliente"),
		@NamedQuery(name = "buscarClientePorNombre", query = "SELECT c FROM Clientes c WHERE c.nombre LIKE :nom") })
public class Clientes implements Serializable {

	private static final long serialVersionUID = 375104952118553886L;

	@Id
	@Column(name = "rut")
	private long rut;
	@Column(name = "nombre", nullable = false)
	private String nombre;

	@Column(name = "rSocial")
	private String rSocial;

	@Column(name = "direccion", nullable = false)
	private String direccion;

	@Column(name = "tel1")
	private String tel1;

	@Column(name = "tel2")
	private String tel2;

	@Column(name = "fax")
	private String fax;

	@Column(name = "cel")
	private String cel;

//	@Email
	@Column(name = "mail")
	private String mail;

	@Column(name = "contacto")
	private String contacto;

	@Column(name = "falta", nullable = false)
	private Date fechaAlta;

	@Column(name = "formaPago")
	private String formaPago;

	@Column(name = "diaPago")
	private String diaPago;

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "cli", targetEntity = Facturas.class)
	// @OneToMany ( fetch=FetchType.LAZY, cascade=CascadeType.PERSIST,
	// mappedBy="auto", targetEntity=Servicio.class)
	private Collection<Facturas> facturas;

	public long getRut() {
		return rut;
	}

	public void setRut(long rut) {
		this.rut = rut;
	}

	public String getNombre() {
		return nombre;
	}

	public void setNombre(String nombre) {
		this.nombre = nombre;
	}

	public String getrSocial() {
		return rSocial;
	}

	public void setrSocial(String rSocial) {
		this.rSocial = rSocial;
	}

	public String getDireccion() {
		return direccion;
	}

	public void setDireccion(String direccion) {
		this.direccion = direccion;
	}

	public String getTel1() {
		return tel1;
	}

	public void setTel1(String tel1) {
		this.tel1 = tel1;
	}

	public String getTel2() {
		return tel2;
	}

	public void setTel2(String tel2) {
		this.tel2 = tel2;
	}

	public String getFax() {
		return fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	public String getCel() {
		return cel;
	}

	public void setCel(String cel) {
		this.cel = cel;
	}

	public String getMail() {
		return mail;
	}

	public void setMail(String mail) {
		this.mail = mail;
	}

	public String getContacto() {
		return contacto;
	}

	public void setContacto(String contacto) {
		this.contacto = contacto;
	}

	public Date getFechaAlta() {
		return fechaAlta;
	}

	public void setFechaAlta(Date fechaAlta) {
		this.fechaAlta = fechaAlta;
	}

	public String getFormaPago() {
		return formaPago;
	}

	public void setFormaPago(String formaPago) {
		this.formaPago = formaPago;
	}

	public String getDiaPago() {
		return diaPago;
	}

	public void setDiaPago(String diaPago) {
		this.diaPago = diaPago;
	}

	public Collection<Facturas> getFacturas() {
		return facturas;
	}

	public void setFacturas(Collection<Facturas> facturas) {
		this.facturas = facturas;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((nombre == null) ? 0 : nombre.hashCode());
		result = prime * result + (int) (rut ^ (rut >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Clientes other = (Clientes) obj;
		if (nombre == null) {
			if (other.nombre != null)
				return false;
		} else if (!nombre.equals(other.nombre))
			return false;
		if (rut != other.rut)
			return false;
		return true;
	}

	@Override
	public String toString() {
		return getNombre();
	}
}
